package mi.top.utils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class CombinationSwing extends JFrame {
    /** 菜单条*/
    private JMenuBar menubar;
    /** 菜单*/
    private JMenu menuFile;
    /** 菜单项*/
    private JMenuItem itemOpen;

    private String title;

    private Integer defaultCloseOperation;

    public CombinationSwing() throws HeadlessException {
        init();
    }

    public CombinationSwing(String title, Integer defaultCloseOperation) throws HeadlessException {
        this.title = title;
        this.setTitle(title);
        this.defaultCloseOperation = defaultCloseOperation;
        this.setDefaultCloseOperation(defaultCloseOperation);

        init();
    }

    public void init() {

        menubar = new JMenuBar();
        menuFile = new JMenu("菜单");
        itemOpen = new JMenuItem("创建");

        menuFile.add(itemOpen);
        menubar.add(menuFile);
        setJMenuBar(menubar);

        itemOpen.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("--");
                String s = JOptionPane.showInputDialog("");
                System.out.println(s);
                if(s == null) {
                    return;
                }

                new CombinationSwing(s, JFrame.HIDE_ON_CLOSE);

            }
        });


        JSplitPane jSplitPane = new JSplitPane();

        //让分割线显示出箭头
        jSplitPane.setOneTouchExpandable(true);

        //操作箭头，重绘图形
        jSplitPane.setContinuousLayout(true);

        //设置分割线方向
        jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);



        JPanel jPanel1 = new RasterSwing().getJPanel();

        JPanel jPanel2 = new AlarmSwing().getJPanel();

        jSplitPane.setDividerLocation(280);

        jSplitPane.setLeftComponent(jPanel1);
        jSplitPane.setRightComponent(jPanel2);

        this.setContentPane(jSplitPane);
        if(defaultCloseOperation == null){
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        this.setVisible(true);
        this.setSize(570, 600);
    }
}
